package com.wpml.product.controller;

import com.wpml.common.util.PageUtils;
import com.wpml.common.util.ResultJson;
import com.wpml.product.entity.BrandModel;
import com.wpml.product.service.BrandService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;


/**
 * 品牌
 */
@RestController
@RequestMapping("/product/brand")
public class BrandController {
    @Resource
    private BrandService brandService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:brand:list")
    public ResultJson list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return ResultJson.ok(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{brandId}")
    //@RequiresPermissions("product:brand:info")
    public ResultJson info(@PathVariable("brandId") Long brandId){
		BrandModel brand = brandService.getById(brandId);

        return ResultJson.ok(brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("product:brand:save")
    public ResultJson save(/*@Validated({AddGroup.class})*/ @RequestBody BrandModel brand){

        brandService.save(brand);

        return ResultJson.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("product:brand:update")
    public ResultJson update(@RequestBody BrandModel brand){
		brandService.updateDetail(brand);

        return ResultJson.ok();
    }
    /**
     * 修改状态
     */
    @PostMapping("/update/status")
    //@RequiresPermissions("product:brand:update")
    public ResultJson updateStatus(@RequestBody BrandModel brand){
        brandService.updateById(brand);

        return ResultJson.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("product:brand:delete")
    public ResultJson delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return ResultJson.ok();
    }

}
